﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Routing;

namespace System.Web.Mvc.Html
{
    /// <summary>
    /// Helper que permite construír una imagen
    /// </summary>
    public static class Images
    {
        /// <summary>
        /// Imagen sin borde
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="imageUrl"></param>
        /// <param name="altText"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static MvcHtmlString ImageNoBorder(this HtmlHelper helper, string imageUrl, string altText, string id = null)
        {
            return Image(helper, imageUrl, altText, new { style = "border: 0px" }, id);
        }

        /// <summary>
        /// Imagen con todas las opciones
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="imageUrl"></param>
        /// <param name="altText"></param>
        /// <param name="htmlAttributes"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static MvcHtmlString Image(this HtmlHelper helper, string imageUrl, string altText, object htmlAttributes, string id = null)
        {
            var builder = new TagBuilder("img");
            if (id != null)
                builder.GenerateId(id);
            builder.MergeAttribute("src", imageUrl);
            builder.MergeAttribute("alt", altText);
            builder.MergeAttribute("title", altText);
            builder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
            var img = builder.ToString(TagRenderMode.SelfClosing);
            return MvcHtmlString.Create(img);
        }
    }
}
